import 'dart:core';
import 'dart:math';
import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:unt/About.dart';
import 'package:unt/Intentpage.dart';
import 'package:unt/RowDemo.dart';


void main() {
  runApp(
    MaterialApp(home: TextHomePage()),
  );
}

class TextHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TextHomePageState();
  }
}

class TextHomePageState extends State<TextHomePage>  with SingleTickerProviderStateMixin{
  late AnimationController _animationController;
  double size = 100;
  late Animation<double>  animation;
  late Color color;
  late Animation _sizeAnimation;
  late Animation _colorAnimation;
  late Animation _opacityAnimation;
  late Animation _radiansAnimation;
  @override
  void initState() {
    super.initState();
    // 第一步创建 AnimationController
    setState(() {
      _animationController = AnimationController(
        vsync: this,
        duration:Duration(seconds: 2),
      );
    });
    // 第二步设置curve值
    animation = CurvedAnimation(parent: _animationController,curve:Curves.linear);
    _sizeAnimation = Tween(begin: 10.0,end: 200.0).animate(animation);
    _colorAnimation = ColorTween(begin: Colors.orange,end:Colors.purple ).animate(animation);
    _opacityAnimation = Tween(begin: 0.0,end: 1.0).animate(animation);
    _radiansAnimation = Tween(begin: 0.0,end: 2*pi).animate(animation);
    _animationController.addListener(() {
      setState(() {
        size = _sizeAnimation.value;
      });
    });
    _animationController.addStatusListener((status) {
      if(status == AnimationStatus.completed){
        _animationController.reverse();
      }else if(status == AnimationStatus.dismissed){
        _animationController.forward();
      }
    });
  }
  /**
   * 1。Animation: 抽象类
   *  *监听动画状态的改变
   *  *value
   *  *status
   *  2。AnimationController继承Animation
   *  *vsync 同步信号
   *  *forward（）： 向前执行动画
   *  *reverse（）： 反转执行动画
   *  3。CurvedAnimation：
   *   *作用 设置动画执行的速率（速度曲线）
   *   4。Tween：设置动画执行的value范围
   *    *begin： 开始值
   *    *end： 结束值
   */
  @override
  Widget build(BuildContext context) {
    // AnimationController(vsync: this);
    return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: const Text("listview"),
          ),
          body:  Center(
              child:Opacity(
                opacity: _opacityAnimation.value,
                child: Transform(
                  transform: Matrix4.rotationZ(_radiansAnimation.value),
                  alignment: Alignment.center,
                  child: Container(
                    width: size,
                    height: size,
                    color: _colorAnimation.value,
                  ),
                ),
              )
            // yjhAnimatedIcon(sizeanimation)
            // Icon(Icons.favorite,color: Colors.red,size: size,)
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.error),
            onPressed: (){
              // _animationController.forward();
              if(_animationController.isAnimating){
                _animationController.stop();
              }else {
                _animationController.forward();
              }
            },
          ),
        )
    );
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _animationController.dispose();
  }
}

